
import java.io.*;
import POJO.*;
import DB.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author Sibrand
 */
public class addStop extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            HttpSession sess = request.getSession();
            TripManager db = new TripManager(DBInfo.getConnection());
            if (request.getMethod().equals("POST") && sess.getAttribute("user") != null && ((User) sess.getAttribute("user")).username != null && request.getParameter("tripid") != null && db.isOwnerOf(Integer.parseInt(request.getParameter("tripid")), ((User) sess.getAttribute("user")).username)) {
                out.println("<div style=\"width:100%; text-align:center;\"><form onfocus = \"initialize()\" name=\"addStopForm\" method=\"POST\" action=\"index.jsp?page=trip&amp;tripid=" + Integer.parseInt(request.getParameter("tripid")) + "&amp;addStop=true\">" +
                        "<table style=\"text-align:left;\" ><tr><th colspan=\"2\"><div  id=\"select_canvas\" style=\"height: 250px; width: 100%;\" ></div></th></tr>"+ 
                        "<tr><td>North:</td><td><input size=\"25\" type=\"text\" id = \"north\" name=\"north\" value=\"\" /></td></tr>" +
                        "<tr><td>East:</td><td><input size=\"25\" type=\"text\" id = \"east\" name=\"east\" value=\"\" /></td></tr>" +
                        "<tr id = \"locationrow\" name = \"locationrow\"><td >Location:</td><td><input size=\"25\" type=\"text\" id = \"location\" name=\"location\" value=\"Unknown location\" /></td></tr>" +
                        "<tr><td>Arrival:</td><td><input size=\"25\" type=\"text\" class=\"date-pick\" id=\"arrival\" name=\"arrival\" value=\"" + db.getStart(Integer.parseInt(request.getParameter("tripid"))) + "\"/></td></tr>" +
                        "<tr><td>Viewable by:</td><td><select name=\"view\"><option value=\"EVERYBODY\" selected=\"selected\">Everybody</option><option value=\"FAMILY\">Friends</option><option value=\"FRIEND\">Family</option></select></td></tr>" +
                        "<tr><td colspan=\"2\" style=\"text-align:center;\"><input type=\"submit\" value=\"Add\" /></td></tr></table></form></div>");
                 
            } else {
                out.print("Unauthorized entrance.");
            }
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
